cap log close

global path = "****"
local name= "treatment_effect_by_state"
local date = "031720"
global logname = "$path/`name'_`date'.log"

clear
set more off
set matsize 11000
cd "$path"
log using "$logname", replace

use "$path/Data/penalty_sample.dta", clear

replace age_2017=0 if age_2017<0

*sample restrictions
keep if age_45_64 == 1 
keep if notall16 == 1


cap erase "cov_state_3_`date'.ster"
cap erase "mort_state_1_`date'.ster"
	

forval i = 1/51{ 

estimates clear
eststo clear

*2017-18 months of coverage effect
reg covered1718 treatment if state_num == `i', cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)*100
estimates save "cov_state_3_`date'.ster", append


*mortality effect

reg dead1718 treatment if state_num == `i', cl(tin) 
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)*100
estimates save "mort_state_1_`date'.ster", append

}

log close
